package com.wc5818.gongzdc.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wc5818.bankSearch.entity.BankReport;
import com.wc5818.common.AjaxResult;
import com.wc5818.gongzdc.entity.WorkReport;
import com.wc5818.gongzdc.mapper.WorkReportMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author jobob
 * @since 2020-03-21
 */
@RestController
@RequestMapping("/gongzdc")
public class WorkReportController {
    @Autowired
    WorkReportMapper workReportMapper;

    @GetMapping("/createNew")
    public Object createNew(String orderNum, Integer baseInfoId, Integer workInfoId) {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setSuccess(false);

        WorkReport workReport = new WorkReport();
        workReport.setOrderNum(orderNum);
        workReport.setBaseInfoId(baseInfoId);
        workReport.setWorkInfoId(workInfoId);
        workReport.setCreateTime(LocalDateTime.now());
        workReport.setWorkResult("1");

        if(workReportMapper.insert(workReport) > 0) {
            ajaxResult.setSuccess(true);
            ajaxResult.setData(workReport.getWorkResult());
        }

        return ajaxResult;
    }

    @GetMapping("/queryByOrderNum")
    public Object queryByOrderNum(String orderNum) {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setSuccess(false);

        List list = workReportMapper.selectList(new QueryWrapper<WorkReport>().eq("orderNum", orderNum));
        if(list != null && list.size() > 0) {
            ajaxResult.setSuccess(true);
            ajaxResult.setData(list.get(0));
        }

        return ajaxResult;
    }
}
